﻿using StoreProject.Enum;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace StoreProject.Forms.UserControls
{
    public partial class ConfigTooBar : ToolStrip
    {
        private ConfigToolButton btnAdd;
        private ConfigToolButton btnUpdate;
        private ConfigToolButton btnDelete;
        private ConfigToolButton btnSave;
        private ConfigToolButton btnQuery;
        private ConfigToolButton btnExit;
        private ConfigToolButton btnCancel;
        private ConfigToolButton btnPrint;
        private ConfigToolButton btnExport;

        public ConfigTooBar()
        {
            InitializeComponent();
            Init();
        }

        public void Init()
        {
            this.Items.Clear();
            btnAdd = new ConfigToolButton(ConfigButtonType.ADD);
            btnUpdate = new ConfigToolButton(ConfigButtonType.UPDATE);
            btnDelete = new ConfigToolButton(ConfigButtonType.DELETE);
            btnSave = new ConfigToolButton(ConfigButtonType.SAVE);
            btnCancel = new ConfigToolButton(ConfigButtonType.CANCEL);
            btnQuery = new ConfigToolButton(ConfigButtonType.QUERY);
            btnPrint = new ConfigToolButton(ConfigButtonType.PRINT);
            btnExport = new ConfigToolButton(ConfigButtonType.EXPORT);
            btnExit = new ConfigToolButton(ConfigButtonType.EXIT);

            //this.Items.AddRange(new ConfigToolButton[] { btnAdd, btnUpdate, btnDelete, btnSave,btnCancel, btnQuery,btnPrint,btnExport, btnExit });


            this.Items.AddRange(new ToolStripItem[] {
                btnExit, CreateSerarator(btnExit),
                btnExport, CreateSerarator(btnExport),
                btnPrint, CreateSerarator(btnPrint),
                btnQuery, CreateSerarator(btnQuery),
                btnCancel, CreateSerarator(btnCancel),
                btnSave, CreateSerarator(btnSave),
                btnDelete,CreateSerarator(btnDelete),
                btnUpdate,CreateSerarator(btnUpdate),
                btnAdd });
        }

        private ToolStripSeparator CreateSerarator(ToolStripItem btn)
        {
            ToolStripSeparator sp = new ToolStripSeparator();
            sp.Tag = btn.Tag;
            sp.Name = "SP" + btn.Tag.ToString();
            return sp;
        }

        private void SetVisiableSeparator(ToolStripItem btn, bool visible)
        {
            ToolStripItem sp = this.Items["SP" + btn.Tag.ToString()];
            if (sp != null)
            {
                sp.Visible = visible;
            }
        }

        public void SetDefaultTooBar()
        {
            foreach (ToolStripItem btn in this.Items)
            {
                btn.Visible = true;
                btn.Enabled = true;
            }
            btnQuery.Visible = false;
            btnExport.Visible = false;
            btnPrint.Visible = false;
            SetVisiableSeparator(btnQuery, false);
            SetVisiableSeparator(btnExport, false);
            SetVisiableSeparator(btnPrint, false);
        }

        public void SetSaveTooBar()
        {
            foreach (ToolStripItem btn in this.Items)
            {
                btn.Visible = false;
            }
            btnSave.Visible = true;
            btnExit.Visible = true;
            SetVisiableSeparator(btnSave, true);
            SetVisiableSeparator(btnExit, true);

        }

        public void SetUpdateTooBar()
        {
            foreach (ToolStripItem btn in this.Items)
            {
                btn.Visible = false;
            }
            btnUpdate.Visible = true;
            btnSave.Visible = true;
            btnCancel.Visible = true;
            btnExit.Visible = true;
            SetVisiableSeparator(btnUpdate, true);
            SetVisiableSeparator(btnSave, true);
            SetVisiableSeparator(btnCancel, true);
            SetVisiableSeparator(btnExit, true);

        }

        /// <summary>
        /// 新增，修改，删除，查询
        /// </summary>
        public void SetQueryTooBar()
        {
            foreach (ToolStripItem btn in this.Items)
            {
                btn.Visible = true;
            }
            btnSave.Visible = false;
            btnCancel.Visible = false;
            btnExport.Visible = false;
            btnPrint.Visible = false;
            btnExit.Visible = false;
            SetVisiableSeparator(btnSave, false);
            SetVisiableSeparator(btnCancel, false);
            SetVisiableSeparator(btnExport, false);
            SetVisiableSeparator(btnPrint, false);
            SetVisiableSeparator(btnExit, false);
        }

        /// <summary>
        /// 新增，查询
        /// </summary>
        public void SetInsertTooBar()
        {
            foreach (ToolStripItem btn in this.Items)
            {
                btn.Visible = true;
            }
            btnSave.Visible = false;
            btnCancel.Visible = false;
            btnExport.Visible = false;
            btnPrint.Visible = false;
            btnExit.Visible = false;
            btnUpdate.Visible = false;
            btnDelete.Visible = false;
            SetVisiableSeparator(btnSave, false);
            SetVisiableSeparator(btnCancel, false);
            SetVisiableSeparator(btnExport, false);
            SetVisiableSeparator(btnPrint, false);
            SetVisiableSeparator(btnExit, false);
            SetVisiableSeparator(btnUpdate, false);
            SetVisiableSeparator(btnDelete, false);
        }

        /// <summary>
        /// 查询
        /// </summary>
        public void SetQueryEx1TooBar()
        {
            foreach (ToolStripItem btn in this.Items)
            {
                btn.Visible = true;
            }
            btnSave.Visible = false;
            btnCancel.Visible = false;
            btnExport.Visible = false;
            btnPrint.Visible = false;
            btnExit.Visible = false;
            btnUpdate.Visible = false;
            btnDelete.Visible = false;
            btnAdd.Visible = false;
            SetVisiableSeparator(btnSave, false);
            SetVisiableSeparator(btnCancel, false);
            SetVisiableSeparator(btnExport, false);
            SetVisiableSeparator(btnPrint, false);
            SetVisiableSeparator(btnExit, false);
            SetVisiableSeparator(btnUpdate, false);
            SetVisiableSeparator(btnDelete, false);
            SetVisiableSeparator(btnAdd, false);
        }


        /// <summary>
        /// 新增，修改，删除，查询，导出，退出
        /// </summary>
        public void SetQueryExportBtnTooBar()
        {
            foreach (ToolStripItem btn in this.Items)
            {
                btn.Visible = true;
            }
            btnSave.Visible = false;
            btnCancel.Visible = false;
            btnPrint.Visible = false;
            SetVisiableSeparator(btnSave, false);
            SetVisiableSeparator(btnCancel, false);
            SetVisiableSeparator(btnExport, false);
            SetVisiableSeparator(btnPrint, false);
        }

        /// <summary>
        /// 新增，删除，查询，退出
        /// </summary>
        public void SetQueryExTooBar()
        {
            foreach (ToolStripItem btn in this.Items)
            {
                btn.Visible = true;
            }
            btnUpdate.Visible = false;
            btnSave.Visible = false;
            btnCancel.Visible = false;
            btnExport.Visible = false;
            btnPrint.Visible = false;
            SetVisiableSeparator(btnUpdate, false);
            SetVisiableSeparator(btnSave, false);
            SetVisiableSeparator(btnCancel, false);
            SetVisiableSeparator(btnExport, false);
            SetVisiableSeparator(btnPrint, false);
        }

        /// <summary>
        /// 修改，查询，退出
        /// </summary>
        public void SetUpdateExTooBar()
        {
            foreach (ToolStripItem btn in this.Items)
            {
                btn.Visible = true;
            }
            btnDelete.Visible = false;
            btnAdd.Visible = false;
            btnSave.Visible = false;
            btnCancel.Visible = false;
            btnExport.Visible = false;
            btnPrint.Visible = false;
            SetVisiableSeparator(btnDelete, false);
            SetVisiableSeparator(btnAdd, false);
            SetVisiableSeparator(btnSave, false);
            SetVisiableSeparator(btnCancel, false);
            SetVisiableSeparator(btnExport, false);
            SetVisiableSeparator(btnPrint, false);
        }

        /// <summary>
        /// 新增,修改，查询，退出
        /// </summary>
        public void SetNoDelTooBar()
        {
            foreach (ToolStripItem btn in this.Items)
            {
                btn.Visible = true;
            }
            btnDelete.Visible = false;
            btnSave.Visible = false;
            btnCancel.Visible = false;
            btnExport.Visible = false;
            btnPrint.Visible = false;
            SetVisiableSeparator(btnDelete, false);
            SetVisiableSeparator(btnSave, false);
            SetVisiableSeparator(btnCancel, false);
            SetVisiableSeparator(btnExport, false);
            SetVisiableSeparator(btnPrint, false);
        }

        /// <summary>
        /// 查询，导出，退出
        /// </summary>
        public void SetQueryExportTooBar()
        {
            foreach (ToolStripItem btn in this.Items)
            {
                btn.Visible = false;
            }
            btnQuery.Visible = true;
            btnExport.Visible = true;
            btnExit.Visible = true;
            SetVisiableSeparator(btnQuery, true);
            SetVisiableSeparator(btnExport, true);
            SetVisiableSeparator(btnExit, true);
        }

        /// <summary>
        /// 查询，退出
        /// </summary>
        public void SetOnlyQueryTooBar()
        {
            foreach (ToolStripItem btn in this.Items)
            {
                btn.Visible = false;
            }
            btnQuery.Visible = true;
            btnExit.Visible = true;
            SetVisiableSeparator(btnQuery, true);
            SetVisiableSeparator(btnExit, true);
        }

        /// <summary>
        /// 查询，打印，导出，退出
        /// </summary>
        public void SetQueryPrintTooBar()
        {
            foreach (ToolStripItem btn in this.Items)
            {
                btn.Visible = false;
            }
            btnQuery.Visible = true;
            btnExport.Visible = true;
            btnPrint.Visible = true;
            btnExit.Visible = true;
            SetVisiableSeparator(btnQuery, true);
            SetVisiableSeparator(btnExport, true);
            SetVisiableSeparator(btnPrint, true);
            SetVisiableSeparator(btnExit, true);
        }

        public void SetNoneTooBar()
        {
            foreach (ToolStripItem btn in this.Items)
            {
                btn.Visible = false;
            }
            btnExit.Visible = true;
            SetVisiableSeparator(btnExit, true);
        }

        /// <summary>
        /// 新增，修改，停用，查询，导出，退出
        /// </summary>
        public void SetQueryStopTooBar()
        {
            foreach (ToolStripItem btn in this.Items)
            {
                btn.Visible = false;
            }
            btnAdd.Visible = true;
            btnUpdate.Visible = true;
            btnDelete.Text = "停用";
            btnDelete.Visible = true;
            btnQuery.Visible = true;
            btnExport.Visible = true;
            btnExit.Visible = true;
        }

        /// <summary>
        /// 查询，删除，退出
        /// </summary>
        public void SetQueryDelTooBar()
        {
            foreach (ToolStripItem btn in this.Items)
            {
                btn.Visible = false;
            }
            btnDelete.Visible = true;
            btnQuery.Visible = true;
            btnExit.Visible = true;
        }

        public void SetBtnDeleteText(string text)
        {
            btnDelete.Text = text;
        }
    }
}
